﻿using System.Drawing;

namespace LineAndLine
{
	/// <summary>
	/// 线段
	/// </summary>
	class LineSegment
	{

		private Point start;

		private Point end;

		/// <summary>
		/// 线段起点
		/// </summary>
		public Point Start
		{
			get { return start; }
			set { start = value; }
		}

		/// <summary>
		/// 线段终点
		/// </summary>
		public Point End
		{
			get { return end; }
			set { end = value; }
		}

		/// <summary>
		/// 线段无参构造器
		/// </summary>
		public LineSegment()
		{
		}

		/// <summary>
		/// 用两个点初始化线段
		/// </summary>
		/// <param name="start">起始点</param>
		/// <param name="end">终止点</param>
		public LineSegment(Point start, Point end)
		{
			Start = start;
			End = end;
		}

		/// <summary>
		/// 判断两个点是否在自身同侧
		/// </summary>
		/// <param name="p1">点1</param>
		/// <param name="p2">点2</param>
		/// <returns>点1和点2是否在自身同侧，若只要有点在线段上，也判断为不在同侧</returns>
		public bool AtSameSide(Point p1, Point p2)
		{
			bool result = false;
			Vector v1 = new Vector(Start, p1);
			Vector v2 = new Vector(Start, p2);
			Vector self = new Vector(this);
			if ((self.CrossProduct(v1) > 0 && self.CrossProduct(v2) > 0) || (self.CrossProduct(v1) < 0 && self.CrossProduct(v2) < 0))
			{
				result = true;
			}
			return result;
		}
	}
}